﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// Motorcycle is a class that inherit <see cref="Ex03.GarageLogic.Vehicle" />  and have also the properties:
    /// 1. Max number of passengers.
    /// 2. If carring dangours metrials.
    /// </summary>
    internal class CommercialVehicle : Vehicle
    {
        private int m_MaxNumberOfPassengers = 0;
        private bool m_CarryDangerousMaterials = false;

        public CommercialVehicle(string i_VehicleModelName, string i_VehicleLicenseNumber, Wheel[] i_WheelsArary, EnergySource i_EnergySource)
            : base(i_VehicleModelName, i_VehicleLicenseNumber, i_WheelsArary, i_EnergySource)
        {
        }

        /// <summary>
        /// Overriding <see cref="Object.ToString"/>
        /// </summary>
        /// <returns>All the info of the commercial vehicle formatted as on string</returns>
        public override string ToString()
        {
            string toString = string.Empty;

            toString = string.Format(@"
{0}
Max number of passengers: {1}
Is carring dangerous materials: {2}"
                , base.ToString()
                , m_MaxNumberOfPassengers
                , m_CarryDangerousMaterials);

            return toString;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.GetSpecificProperties"/>
        /// </summary>
        /// <returns> List of strings that represnts messages for the Ui </returns>
        public override List<string> GetSpecificProperties()
        {
            List<string> listOfspecificProperties = new List<string>();

            listOfspecificProperties.Add("Enter max of passengers: ");
            listOfspecificProperties.Add("Enter if you carraing dangours materials (True/False): ");

            return listOfspecificProperties;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.SetSpecificProperties"/> sets commercial vehicle his specific properties
        /// </summary>
        /// <param name="i_ListOfSpecificVehiclePropertiesFromUser">List of user inputs from the UI </param>
        public override void SetSpecificProperties(List<string> i_ListOfSpecificVehiclePropertiesFromUser)
        {
            int numberOfPassengersResult;
            bool isParseCorrect = false;
            bool isCarryDangerousMaterials = false;
            
            isParseCorrect = int.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[0], out numberOfPassengersResult);            
            if (isParseCorrect)
            {
                if (numberOfPassengersResult < 0)
                {
                    throw new ArgumentException("negative number of passengers is not allowed");
                }
                else
                {
                    m_MaxNumberOfPassengers = numberOfPassengersResult;
                }
            }
            else 
            {
                throw new FormatException("it is not a number");
            }

            isParseCorrect = bool.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[1], out isCarryDangerousMaterials);
            if (isParseCorrect)
            {
                m_CarryDangerousMaterials = isCarryDangerousMaterials;
            }
            else
            {
                throw new FormatException("enter true or false");
            }
        }
    }
}
